import java.security.PublicKey;
import java.util.Scanner;

public class Main {
    public static int[] num1 = new int[4];
    public static int[] num2 = new int[4];
    public static Scanner sc = new Scanner(System.in);
      public static   int count = 0;

    public static void main(String[] args) {
        getNum();
        cainum();

    }
    //进行猜数字
    public static void cainum(){
        while (count < 5) {
            int a = 0;
            int b = 0;
            intputNum();
            for (int i = 0; i < num1.length; i++) {
                for (int j = 0; j < num2.length; j++) {
                    if (num1[i] == num2[j] && i == j) {
                        a++;
                    }
                    if (num1[i] == num2[j] && i != j) {
                        b++;
                    }
                }
            }
            System.out.println("a:" + a + "b:" + b);
            if (a == 4) {
                System.out.println("猜对了");
                break;
            }
            count++;
            System.out.println("还剩" + (5 - count) + "次机会");
        }

    }

    // 判断输入数字是否正确。
    public static void intputNum() {
        try {
            for (int i = 0; i < num1.length; i++) {
                System.out.println("请输入底" + (i + 1) + "个数");
                int num = sc.nextInt();

                boolean repeat = false; // 假设 num 没有重复
                for (int j = 0; j < i; j++) {
                    if (num2[j] == num) {
                        repeat = true;
                        System.out.println("输入重复数字请重新输入");
                        i--;
                        break;
                    }
                }
                if (!repeat) {
                    num2[i] = num;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("输入非法数值请重新输入");
            sc.next();
            intputNum();
        }

    }

    //获取随机数
    public static void getNum() {
        for (int i = 0; i < num1.length; i++) {
            int num = (int) (Math.random() * 10); // 随机数
            boolean repeat = false; // 假设 num 没有重复
            for (int j = 0; j < i; j++) { //
                if (num1[j] == num) {
                    repeat = true;
                    i--;
                    break;
                }
            }
            if (!repeat) {
                num1[i] = num;
            }
        }
    }
}
